package com.xuzhijie.pms.controller;


import com.xuzhijie.pms.common.Result;
import com.xuzhijie.pms.entity.Pet;
import com.xuzhijie.pms.entity.Repair;
import com.xuzhijie.pms.service.IRepairService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 许志杰
 * @since 2024-02-17
 */
@RestController
@RequestMapping("/repair")
public class RepairController {

    @Autowired
    private IRepairService service;

    @GetMapping("/page")
    public Result findPage(@RequestParam Integer page,
                           @RequestParam Integer size,
                           @RequestParam Integer repairType,
                           @RequestParam Integer repairProgress,
                           @RequestParam Integer source) {

        return service.findPage(page, size,repairType,repairProgress,source);
    }

    @PostMapping("/addrepair")
    public Result addrepair(@RequestBody Map<String,Object> request){
        System.out.println(request);
        String description = request.get("description").toString();
        String type = request.get("type").toString();
        String phone = request.get("phone").toString();
        String images = request.get("images").toString();
        String address = request.get("address").toString();
        return service.addrepair(description,type,phone,images,address);
    }

    @GetMapping("/repairById")
    public Result feedbackInfoById(@RequestParam String id){
        Repair byId = service.getById(id);

        return Result.success(byId);
    }

    @PostMapping("/cgstatus")
    public Result changeStatus(@RequestBody Map<String,Object> request){
        System.out.println(request);
        String id = request.get("id").toString();
        Repair byId = service.getById(id);
        byId.setRepairProgress(2);
        service.saveOrUpdate(byId);
        return Result.success();
    }


}

